package com.eshop.modules.system.service.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import java.util.Set;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import com.eshop.modules.system.domain.Role;
import com.eshop.common.mapper.CoreMapper;

@Repository
public interface RoleMapper extends CoreMapper<Role>
{
    @Select({ "SELECT r.id,r.create_time,r.data_scope,r.`level`,r.`name`,r.permission,r.remark FROM role r LEFT OUTER JOIN users_roles u1 ON r.id = u1.role_id LEFT OUTER JOIN user u2 ON u1.user_id = u2.id WHERE u2.id = #{id}" })
    Set<Role> findByUsers_Id(@Param("id") final Long id);
    
    @Delete({ "delete from roles_menus where menu_id = #{id}" })
    void untiedMenu(@Param("id") final Long id);
    
    @Select({ "select m.* from role m LEFT JOIN users_roles t on m.id= t.role_id LEFT JOIN `user` r on r.id = t.user_id where r.id = #{id}" })
    List<Role> selectListByUserId(@Param("id") final Long id);
}
